<?php
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
include '../../../include/cp_header.php';

include XOOPS_ROOT_PATH."/modules/xoopspoll/include/constants.php";
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
include_once XOOPS_ROOT_PATH."/class/xoopslists.php";
include_once XOOPS_ROOT_PATH."/class/xoopsblock.php";
include_once XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspoll.php";
include_once XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspolloption.php";
include_once XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspolllog.php";
include_once XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspollrenderer.php";

if ( isset($_GET['op']) ) {
  $op = $_GET['op'];
} elseif ( isset($_POST['op']) ) {
  $op = $_POST['op'];
} else {
  $op = 'list';
}

switch ( $op ) {
  case 'list':
    include XOOPS_ROOT_PATH.'/modules/xoopspoll/admin/include/list.php';
    break;
  case 'edit':
    include XOOPS_ROOT_PATH.'/modules/xoopspoll/admin/include/edit.php';
    break;
  case 'delete':
  case 'delete_ok':
    include XOOPS_ROOT_PATH.'/modules/xoopspoll/admin/include/delete.php';
    break;
  case 'log':
    include XOOPS_ROOT_PATH.'/modules/xoopspoll/admin/include/log.php';
    break;
  case 'add':
    include XOOPS_ROOT_PATH.'/modules/xoopspoll/admin/include/add.php';
    break;
  case 'restart':
  case 'restart_ok':
    include XOOPS_ROOT_PATH.'/modules/xoopspoll/admin/include/restart.php';
    break;
  case 'update':
    include XOOPS_ROOT_PATH.'/modules/xoopspoll/admin/include/update.php';
    break;
  case 'addmore':
    include XOOPS_ROOT_PATH.'/modules/xoopspoll/admin/include/addmore.php';
    break;
  case 'savemore':
    include XOOPS_ROOT_PATH.'/modules/xoopspoll/admin/include/savemore.php';
    break;
  case 'save':
    include XOOPS_ROOT_PATH.'/modules/xoopspoll/admin/include/save.php';
    break;
  case 'quickupdate':
    $posta = array('poll_id','old_display','display','old_weight','weight');
    foreach ( $posta as $pa ) {
      $$pa = $_POST[$pa];
    }
    $count = count($poll_id);
    for ( $i = 0; $i < $count; $i++ ) {
      $display[$i] = empty($display[$i]) ? 0 : 1;
      $weight[$i] = empty($weight[$i]) ? 0 : intval($weight[$i]);
      
      if ( $display[$i] != $old_display[$i] || $weight[$i] != $old_weight[$i] ) {
        $poll = new XoopsPoll(intval($poll_id[$i]));
        $poll->setVar("display", $display[$i]);
        $poll->setVar("weight", $weight[$i]);
        $poll->store();
      }
    }
    include_once XOOPS_ROOT_PATH.'/class/template.php';
    xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
    redirect_header("index.php",1,_AM_DBUPDATED);
    break;
}
?>
